<?php
class test{
    public $a=1;
}
function test(){
     $test=new test();
    return function () use($test){
           echo $test->a++;
    };
}
$a=test();
$a();
$a();
$a();
$b=test();
$b();
$a();